package com.ruoyi.visitor.controller;

import java.util.List;

import com.ruoyi.visitor.domain.VisitorAppointmentStaff;
import com.ruoyi.visitor.service.IVisitorAppointmentStaffService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 随访人员Controller
 * 
 * @author ruoyi
 * @date 2025-06-01
 */
@Controller
@RequestMapping("/system/staff")
public class VisitorAppointmentStaffController extends BaseController
{
    private String prefix = "system/staff";

    @Autowired
    private IVisitorAppointmentStaffService visitorAppointmentStaffService;

    @RequiresPermissions("system:staff:view")
    @GetMapping()
    public String staff()
    {
        return prefix + "/staff";
    }

    /**
     * 查询随访人员列表
     */
    @RequiresPermissions("system:staff:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VisitorAppointmentStaff visitorAppointmentStaff)
    {
        startPage();
        List<VisitorAppointmentStaff> list = visitorAppointmentStaffService.selectVisitorAppointmentStaffList(visitorAppointmentStaff);
        return getDataTable(list);
    }

    /**
     * 导出随访人员列表
     */
    @RequiresPermissions("system:staff:export")
    @Log(title = "随访人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VisitorAppointmentStaff visitorAppointmentStaff)
    {
        List<VisitorAppointmentStaff> list = visitorAppointmentStaffService.selectVisitorAppointmentStaffList(visitorAppointmentStaff);
        ExcelUtil<VisitorAppointmentStaff> util = new ExcelUtil<VisitorAppointmentStaff>(VisitorAppointmentStaff.class);
        return util.exportExcel(list, "随访人员数据");
    }

    /**
     * 新增随访人员
     */
    @RequiresPermissions("system:staff:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存随访人员
     */
    @RequiresPermissions("system:staff:add")
    @Log(title = "随访人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VisitorAppointmentStaff visitorAppointmentStaff)
    {
        return toAjax(visitorAppointmentStaffService.insertVisitorAppointmentStaff(visitorAppointmentStaff));
    }

    /**
     * 修改随访人员
     */
    @RequiresPermissions("system:staff:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VisitorAppointmentStaff visitorAppointmentStaff = visitorAppointmentStaffService.selectVisitorAppointmentStaffById(id);
        mmap.put("visitorAppointmentStaff", visitorAppointmentStaff);
        return prefix + "/edit";
    }

    /**
     * 修改保存随访人员
     */
    @RequiresPermissions("system:staff:edit")
    @Log(title = "随访人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VisitorAppointmentStaff visitorAppointmentStaff)
    {
        return toAjax(visitorAppointmentStaffService.updateVisitorAppointmentStaff(visitorAppointmentStaff));
    }

    /**
     * 删除随访人员
     */
    @RequiresPermissions("system:staff:remove")
    @Log(title = "随访人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(visitorAppointmentStaffService.deleteVisitorAppointmentStaffByIds(ids));
    }
}
